package models;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;

import play.db.jpa.Model;

/**
 *
 *
 *
 * A class representing the notification system to be provided to the Idea Developers.
 * 
 *
 *
 *
 *
 *
 * @author Sharif
 * @version 0.4
 *
 *
 */
@Entity

public class Notification extends Model{



   public String body;/*the action */
//   @ManyToOne
//   public IdeaDeveloper reciever;/*whoever is following something or has sent a request   */
   @ManyToOne
   public IdeaDeveloper sender;/*the actioncreator  */
   public Date date;/*date of the action */
   public boolean viewed;/*specifies whether the notification*/

    @ManyToOne IdeaDeveloper notificationsViewer;/*gets the idea developers who has the notifications list*/
    @ManyToOne Organization hasNotifications;/*gets the organization who has the notifications list*/
//     public String getBody() {
//        return body;
//    }
//
//    public void setBody(String body) {
//        this.body = body;
//    }
//
//    public Date getDate() {
//        return date;
//    }
//
//    public void setDate(Date date) {
//        this.date = date;
//    }
//     public IdeaDeveloper getSender() {
//        return sender;
//    }
//
//    public void setSender(IdeaDeveloper sender) {
//        this.sender = sender;
//    }
//
//    public IdeaDeveloper getReciever() {
//        return reciever;
//    }
//
//    public void setReciever(IdeaDeveloper reciever) {
//        this.reciever = reciever;
//    }
//
//    public boolean getViewed() {
//        return viewed;
//    }
//
//    public void setViewed(boolean viewed) {
//        this.viewed = viewed;
//    }
//    public IdeaDeveloper getNotificationsViewer(){
//        return notificationsViewer;
//    }
//       public void setNotificationsViewer(IdeaDeveloper notificationsViewer){
//        this.notificationsViewer=notificationsViewer;
//    }

              /**
     * This method is used to add a notification to the  idea developer's 1 list of notification in the system
     *when any idea developer 2 affects the idea developer 1 , or anything idea developer 1 follows in any way.
     * @param body
     *            represents the name desired for action performed by the ideadeveloper
     * @param reciever
     *            represents the name of the idea developer that is has affected the idea developer
     * @param sender
     *           represents the name of the idea developer that has affected any idea developer
     * @param date
     *           represents the date of the action
     *
     */
    public  Notification(String body, IdeaDeveloper reciever , IdeaDeveloper sender,Date date){
        this.body=body;
        this.notificationsViewer=reciever;
        this.sender=sender;
        this.date=date;
        this.viewed=false;
        //this.save();
        //this.notificationsViewer.notifications.add(this);
       //this.notificationsViewer.save();
    }

               /**
     * This method is used to add a notification to the  idea developer's 1 list of notification in the system
     *when any idea developer 2 affects the idea developer 1 , or anything idea developer 1 follows in any way(this one saves the notification at the ideaDeveloper)
     * @param body
     *            represents the name desired for action performed by the ideadeveloper
     * @param reciever
     *            represents the name of the idea developer that is has affected the idea developer
     * @param sender
     *           represents the name of the idea developer that has affected any idea developer
     * @param date
     *           represents the date of the action
     *
     */
    public static void notify(String body, IdeaDeveloper reciever , IdeaDeveloper sender,Date date){
Notification N=new Notification(body,reciever,sender,date);
N.save();
N.notificationsViewer.notifications.add(N);
N.notificationsViewer.save();
    }

        /**
     * This method is used to add a notification to the  organization's list of notification in the system
     *when an idea developer affects the organization in any way
     * @param body
     *            represents the name desired for action performed by the ideadeveloper
     * @param reciever
     *            represents the organization that is has affected the idea developer
     * @param sender
     *           represents the name of the idea developer that has affected any organization
     * @param date
     *           represents the date of the action
     *
     */
      public  Notification(String body, Organization reciever , IdeaDeveloper sender,Date date){
        this.body=body;
        this.sender=sender;
        this.date=date;
        this.hasNotifications=reciever;
        this.viewed=false;
       // this.save();
        this.hasNotifications.notifications.add(this);
       // this.hasNotifications.save();

        

    }

    



}
